<meta title="商品管理"/>
<div class="p">
    <div class="m-b clearfix">
        <form class="form-inline pull-left" id="form">
            <input autocomplete="off" type="text" class="form-control input-sm" placeholder="输入商品名称" style="width:200px;" name="keywords" />
            <select class="form-control input-sm" s="select" s-build="S.get('/api/shopcat/list/0')" name="shopcatId">
                <option value="">一级分类</option>
            </select>
            <label class="control-label">价格：</label>
            <input autocomplete="off" type="number" class="form-control input-sm" placeholder="" style="width:80px;" name="startPrice" /> -
            <input autocomplete="off" type="number" class="form-control input-sm" placeholder="" style="width:80px;" name="endPrice" />
            <input autocomplete="off" type="hidden" name="page" id="page" value="1"/>
            <select class="form-control input-sm" s="select" name="sort">
                <option value="">排序</option>
                <option value="PRICE_ASC">价格从低到高</option>
                <option value="PRICE_ASC">价格从高到低</option>
                <option value="SALES_DESC">销量</option>
                <option value="LIST_TIME_DESC">上架时间</option>
                <option value="UPDATE_TIME_DESC">更新时间</option>
            </select>
            <select class="form-control input-sm" s="select" s-build="S.get('/api/enum/valuesMap/core.enums.CommissionItemStatus?igNames=DELETED')"
                    name="status">
                <option value="">状态</option>
            </select>
            <button type="button" class="btn btn-default btn-sm" s-click="$page.node.val(1); $commissionItemsGrid.refresh()">查询</button>
        </form>
        <div class="pull-right">
            <div class="btn-group">
                <a href="javascript:;" class="btn btn-default btn-sm"
                   s-click="add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>
            <a href="javascript:;" class="btn btn-primary btn-outline btn-sm"
               s-click="clean()">清理</a>
            <a href="javascript:;" class="btn btn-success btn-outline btn-sm"
               s-click="setStatus('ONSALE')">上架</a>
            <a href="javascript:;" class="btn btn-info btn-outline btn-sm"
               s-click="setStatus('INSTOCK')">下架</a>
            <a href="javascript:;" class="btn btn-danger btn-outline btn-sm"
               s-click="setStatus('DELETED')">删除</a>
            <a href="javascript:;" class="btn btn-default btn-sm s-loading-icon "
               s-click="return $commissionItemsGrid.refresh()">
                <i class="fa fa-refresh s-loading-spinner"></i>
            </a>
        </div>
    </div>
    <div id="commissionItemsGrid"
         s='datac,nda,check'
         s-data="S.get('/api/commissionItem/search', $form.node.serialize())">
        <table class="table table-striped table-bordered table-hover table-middle">
            <tr>
                <th>
                    <label class="s-checkbox">
                        <input autocomplete="off" type="checkbox" s-check-role="checkall-h"/>
                        <span class="s-checkbox-indicator"></span>
                    </label>
                </th>
                <th>名称</th>
                <th>价格</th>
                <th>原价</th>
                <th>券值</th>
                <th>优惠券</th>
                <th>推荐</th>
                <th>佣金</th>
                <th>平台</th>
                <th>分类</th>
                <th>创建时间</th>
                <th>更新时间</th>
                <th>上架时间</th>
                <th>下架时间</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop" s-data-filter="'results'">
            <tr s-loop-role="empty">
                <td colspan="16">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s-check-role="i" s="datac" class="commissionItem">
                <td>
                    <label class="s-checkbox">
                        <input autocomplete="off" type="checkbox" s-check-role="h" />
                        <span class="s-checkbox-indicator"></span>
                    </label>
                </td>
                <td s="tpl">
                    <span>[{%=this.id%}]</span>
                    <a href="{%=this.couponClickUrl ? this.couponClickUrl : this.sourceItemUrl%}"
                       target="_blank" external>{%=this.title%}</a>
                </td>
                <td name="price"></td>
                <td name="originPrice"></td>
                <td name="couponValue"></td>
                <td name="couponInfo"></td>
                <td s="tpl">
                    {%if(this.recommend){%}
                    <label class="label label-success">推荐</label>
                    {%}else{%}
                    <label class="label label-info">普通</label>
                    {%}%}
                </td>
                <td s="tpl">
                    {%if(this.highCommission){%}
                    <label class="label label-warning">{%=this.commissionRate%}%</label>
                    {%}else{%}
                    <label class="label label-info">{%=this.commissionRate%}%</label>
                    {%}%}
                </td>
                <td name="ecomPlatTitle"></td>
                <td>
                    <span name="shopcatTitle"></span>
                    <span name="sourceCatId"></span>
                </td>
                <td name="createTime"></td>
                <td name="updateTime"></td>
                <td name="listTime"></td>
                <td name="delistTime"></td>
                <td s="tpl">
                    {%if(this.status=='ONSALE'){%}
                    <label class="label label-success">{%=this.status%}</label>
                    {%}else{%}
                    <label class="label label-default">{%=this.status%}</label>
                    {%}%}
                </td>
                <td class="text-right" s="tpl">

                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="16" class="text-right">
                    <ul s="pagination"
                        s-pagination="{action:function(){$page.node.val(this); $commissionItemsGrid.refresh()}}"
                        class="pagination pagination-sm">
                    </ul>
                    共有<span name="total"></span>个数据
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script type="text/javascript">

    function setStatus(status) {
        S.confirm("确定操作吗？").done(function() {
            var ids = $commissionItemsGrid.getCheckedData("id");
            if(ids.length == 0) {
                S.toast("请先选择要操作的数据")
                return;
            }
            S.put("/api/commissionItem/status/" + status, {ids: ids}).done(function() {
                S.toast("操作完成")
                $commissionItemsGrid.refresh();
            })
        })
    }

    function clean() {
        S.put("/api/commissionItem/clean").done(function() {
            S.toast("操作完成")
            $commissionItemsGrid.refresh();
        })
    }

</script>